/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ages.test

import com.ages.entity.Actor
import com.ages.env.Options
import com.ages.graphics.GLDraw
import com.ages.graphics.Sprite
import com.ages.graphics.SpriteBuffer
import com.ages.graphics.ViewportSwitcher
import com.ages.math.Vector
import com.ages.math.Vector3D
import com.sun.opengl.util.GLUT
import javax.media.opengl.GL
import scala.util.Random

class Box(p:Vector3D) extends Actor{
  pos = p
  private val SIZE:Int = 20
  private val sprite = new Sprite("/com/ages/test/res/Tree.png",1,1)
  def think(){
    val r:Random = new Random(System.currentTimeMillis)
    r.setSeed(System.nanoTime)
    val middleOfScreen = Vector3D(Options.width/2,Options.height/2,0)
    val v:Vector = Vector3D(r.nextDouble*(0.5-r.nextDouble),r.nextDouble*(0.5-r.nextDouble),0)
    val offset = (middleOfScreen minus pos).length
    if(offset>300)
      pos = middleOfScreen
    vel = vel plus (v dot 4.0)
    vel = vel dot 0.9
    pos = pos plus vel
  }
  def draw(gl:GL)
  {
    
    val spot = Vector3D(pos.X,pos.Y,1)
    val box = () =>{
          gl.glEnable(GL.GL_BLEND);
//     Select blending function
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glColor4d(1,1,1,0.3)
      sprite.drawWithoutDisplaylist(gl, 0, 0)
    }
    gl.glDisable(GL.GL_LIGHTING)
    ViewportSwitcher.setup2DView(gl)
    
    GLDraw draw box at spot on gl
  }
  
}
